package com.zucc.controller;

import com.zucc.controller.req.ExperimentAddReq;
import com.zucc.controller.req.ExperimentModifyReq;
import com.zucc.controller.req.ExperimentSearchReq;
import com.zucc.controller.resp.ExperimentResp;
import com.zucc.service.ExperimentService;
import com.zucc.service.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : charspan
 * @Description :
 * @create : 2022-05-22 9:18 上午
 */
@RestController
@Slf4j
@RequestMapping("/v1/api/experiments")
@Api(tags = "实验项目卡管理")
public class ExperimentController {
    @Resource
    private ExperimentService experimentService;

    @ApiOperation(value = "新增实验项目卡")
    @PostMapping
    void add(@RequestBody @Validated ExperimentAddReq req) {
        experimentService.add(req);
    }

    @ApiOperation(value = "处理实验项目卡")
    @PutMapping
    void modify(@RequestBody @Validated ExperimentModifyReq req) {
        experimentService.modify(req);
    }

    @ApiOperation(value = "删除实验项目卡")
    @ApiImplicitParam(paramType = "path", name = "id", value = "实验项目卡编号", dataType = "Long", example = "1", required = true)
    @DeleteMapping("/{id}")
    void deleteOne(@PathVariable Long id) {
        experimentService.deleteOne(id);
    }

    @ApiOperation(value = "实验项目卡分页")
    @PostMapping("/page")
    PageData<ExperimentResp> page(@RequestBody @Validated ExperimentSearchReq req) {
        return experimentService.page(req);
    }

}
